
require('@/js/publiclayouts.js')

require('./index.styl')
require('./layouts/indexbanner.styl')
require('./layouts/indexshanggou.styl')
require('./layouts/indexmobile.styl')
require('./layouts/indexhouseele.styl')

import $ from 'jquery'

var Swiper = require('swiper/swiper-bundle.js')

process.env.NODE_ENV == 'development' && require('@/mock')

new Swiper('.index-menu-banner-swiper', {
    effect: 'fade',
    loop:true,
    autoplay:true,
    delay:5000,
    pagination: {
      el: '.swiper-pagination',
      clickable: true,
    },
    navigation: {
      nextEl: '.swiper-button-next',
      //prevEl: '.swiper-button-prev',
    },
});

var shangouTime = new Date();
var year = shangouTime.getFullYear(),
    month = shangouTime.getMonth(),
    day = shangouTime.getDate();
    var target_his = new Date(year, month, day + 1);

var span_hours = document.querySelector('.hour')
var span_minutes = document.querySelector('.minutes')
var span_second = document.querySelector('.second')

function shangoutime() {
    let thattime = Math.floor(target_his.getTime()/1000);
    let cur = Math.floor((new Date().getTime())/1000);
    let df = thattime-cur;
    let h = Math.floor(df/3600);
    let m = Math.floor((df-h*3600)/60);
    let s = Math.floor((df-h*3600-m*60));


    if(h < 10) h = '0'+h;
    if(m < 10) m = '0'+m;
    if(s < 10) s = '0'+s;
    span_hours.innerHTML = h;
    span_minutes.innerHTML = m;
    span_second.innerHTML = s;
    
}

setInterval(shangoutime,1000);


/**
 * 闪购的swiper
 */
new Swiper('.shanggou-swiper', {
    slidesPerView: 4,
    slidesPerGroup: 4,
    loop:true,
    autoplay:{
        delay:10000,
    },
    speed:1000,
    spaceBetween: 15,
    navigation: {
        prevEl: '.shangou-button-prev',
        nextEl: '.shangou-button-next',
    },
});


/**
 * 家电
 * 热门 电视影音的tab切换
 */
var tabitems = document.querySelectorAll('.tab-item');
var tabitemcontents = document.querySelectorAll('.tab-item-content');
for(let i=0; i<tabitems.length; i += 1) {
    let item = tabitems[i];
    let itemcontent = tabitemcontents[i];
    item.addEventListener('mouseenter', function(e) {
        $(item).addClass('tabfocus').siblings().removeClass('tabfocus');
        $(itemcontent).addClass('tabshow').siblings().removeClass('tabshow');
    })
}